package console

class Console {
    def static readLine() {
        Scanner sc = new Scanner(System.in);
        return sc.nextLine()
    }

    def static readString() {
        return getNextToken()
    }

    def static readInteger() {
        return getNextToken().toInteger()
    }

    def static readDouble() {
        return getNextToken().toDouble()
    }

    def static readBoolean() {
        return (getNextToken() == "true")
    }

    private static String getNextToken() {
        if (inputLine == null)
            readInputLine()

        while (inputIndex == numberOfTokens)
            readInputLine()
        return inputTokens[inputIndex++]
    }

    private static String getNextLine() {
        if (inputLine == null) {
            readInputLine()
        }

        while (inputIndex == numberOfTokens) {
            readInputLine()
        }

        def line = inputTokens[inputIndex..<numberOfTokens].join(' ')
        inputIndex = numberOfTokens
        return line
    }

    private static void readInputLine() {
        inputLine = System.in.readLines('')
        inputTokens = inputLine.tokenize()
        numberOfTokens = inputTokens.size()
        inputIndex = 0
    }

    private static String inputLine = null
    private static List inputTokens = null
    private static int numberOfTokens = 0
    private static int inputIndex = -1


}
